<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>php + mysql questionnaire survey install</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
include("config.php");
if($con=@mysql_connect($host,$user,$password))
{
	echo "<div class=name><ul><li class=title>php + mysql questionnaire survey </p></li>\n";
	echo "<li>Connecting to MySQL database server ...<span class='red'>Succeed!</span></li>";

	mysql_query("SET NAMES 'UTF8'",$con);
	if(!mysql_select_db($db,$con))
	{    
		if(mysql_query("CREATE DATABASE `$db`;",$con))
		{
			echo "<li>Creating database <b>$db</b> ...<span class='red'>Succeed!</span><br></li>\n";
			mysql_select_db($db,$con);
		}	
		else
		{
			echo "<li>Creating database <b>$db</b>...<span class='red'>failed</span>... Permission denied</li>";
		}
	}   
	if(mysql_query("CREATE TABLE `vote_title` (
			`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
			`title` VARCHAR( 150 ) NOT NULL ,
			`options` set('a','b') DEFAULT NULL	) CHARACTER SET UTF8",$con) )
	{
		echo "<li>Creating table <b>vote_title</b>...<span class='red'>Succeed!</span></li>\n";
	}	
	else
	{
		echo "<li>Creating table <b>vote_title</b>...<span class='red'>failed</span>... the table existed?</li>";
	}
	if(mysql_query("CREATE TABLE `vote_ip` (
			`id` int(4) NOT NULL auto_increment,
			`ip` varchar(40) NOT NULL,
			PRIMARY KEY  (`id`)	) CHARACTER SET UTF8",$con))
	{
		echo "<li>Creating table <b>vote_ip</b>...<span class='red'>Succeed!</span></li>\n";
	}	
	else
	{
		echo "<li>Creating table<b>vote_ip</b>...<span class='red'>failed</span>... the table existed?</li>";
	}
	if(mysql_query("CREATE TABLE `vote_choice` (
			`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
			`choice` VARCHAR( 100 ) NOT NULL ,
			`titleid` INT( 10 ) DEFAULT NULL ,
			`num` INT( 80 ) DEFAULT '0',
			`IsOptions` SET('a','b') DEFAULT NULL ) CHARACTER SET UTF8",$con))
			//`IsOptions` SET('a','b') DEFAULT NULL, FULLTEXT KEY `choice` (`choice`)) TYPE=MyISAM AUTO_INCREMENT=22 CHARACTER SET UTF8",$con))
	{
		echo "<li>Creating table <b>vote_choice</b>...<span class='red'>Succeed!</span></li>\n";
	}	
	else
	{
		echo "<li>Creating table <b>vote_choice</b>...<span class='red'>failed</span>... the table existed?</li>";
	}
	if(mysql_query("CREATE TABLE `vote_users` (
			`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
			`admin_name` VARCHAR( 20 ) NOT NULL ,
			`password` VARCHAR( 20 ) NOT NULL) CHARACTER SET UTF8",$con))
	{
		echo "<li>Creating table <b>vote_users</b>...<span class='red'>Succeed!</span></li>\n";
		if(mysql_query("INSERT INTO `vote_users` (admin_name,password) VALUES ('admin', 'admin')",$con))
			echo "<li>Initial the Administractor...<span class='red'>Succeed!</span></li>\n";
	}	
	else
	{
		echo "<li>Creating table <b>vote_users</b>...<span class='red'>failed</span>... the table existed?</li>";
	}
	mysql_close();
	echo "<li class=title><a href='login.php'>If all tables are created successfully, click to login page</a></li></ul></div>";
}
else
{
	echo "<div class=name><ul><li class=title>php + mysql questionnaire survey system</p></li>Can not connect to MySql Server, check 'config.php' again!</li></ul></div>";
}
?>
</body>
</html>
